package com.assessment.mapper;

import com.assessment.model.entity.AssessmentRelation;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 评分关系Mapper接口
 */
public interface AssessmentRelationMapper extends BaseMapper<AssessmentRelation> {

    /**
     * 查询教师的评分任务
     */
    @Select("SELECT r.*, t.name as assessee_name, d.name as department_name, p.name as position_name " +
            "FROM t_assessment_relation r " +
            "INNER JOIN t_teacher t ON r.assessee_id = t.id " +
            "INNER JOIN t_department d ON t.department_id = d.id " +
            "INNER JOIN t_position p ON t.position_id = p.id " +
            "WHERE r.assessor_id = #{assessorId} AND r.period_id = #{periodId} AND r.deleted = 0 " +
            "ORDER BY r.assess_status, t.department_id, t.name")
    List<AssessmentRelation> findTeacherTasks(@Param("assessorId") Integer assessorId, @Param("periodId") Integer periodId);

    /**
     * 查询教师的被评记录
     */
    @Select("SELECT r.*, t.name as assessor_name " +
            "FROM t_assessment_relation r " +
            "INNER JOIN t_teacher t ON r.assessor_id = t.id " +
            "WHERE r.assessee_id = #{assesseeId} AND r.period_id = #{periodId} AND r.deleted = 0 " +
            "ORDER BY r.assess_status, t.department_id, t.name")
    List<AssessmentRelation> findTeacherAssessed(@Param("assesseeId") Integer assesseeId, @Param("periodId") Integer periodId);
}
